package dljs.classes;

import dljs.images.MyResources;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.ArrayList;
import javax.swing.GrayFilter;

/**
 *
 * @author vova
 */
public class CardRenderer {
    
    public CardRenderer(String suitSet) throws IOException{
        m_imgListSpades = new ArrayList<BufferedImage>();
        m_imgListClubs = new ArrayList<BufferedImage>();
        m_imgListDiamonds = new ArrayList<BufferedImage>();
        m_imgListHearts = new ArrayList<BufferedImage>();        
        for (int i=2; i<15; i++) {            
                m_imgListSpades.add(MyResources.instance().getCardImage(String.format("%1$02ds.gif", i),suitSet));
                m_imgListClubs.add(MyResources.instance().getCardImage(String.format("%1$02dc.gif", i),suitSet));
                m_imgListDiamonds.add(MyResources.instance().getCardImage(String.format("%1$02dd.gif", i),suitSet));
                m_imgListHearts.add(MyResources.instance().getCardImage(String.format("%1$02dh.gif", i),suitSet));            
        }
    }
    
    public boolean renderCard(int x, int y, Graphics g, CCard aCard) {
        if (aCard == null) return false;
        
        Image img = null;
        if (aCard.getSuite() == ECardSuite.SPADES) img = m_imgListSpades.get(aCard.getRank()-2);
        if (aCard.getSuite() == ECardSuite.CLUBS) img = m_imgListClubs.get(aCard.getRank()-2);
        if (aCard.getSuite() == ECardSuite.DIAMONDS) img = m_imgListDiamonds.get(aCard.getRank()-2);
        if (aCard.getSuite() == ECardSuite.HEARTS) img = m_imgListHearts.get(aCard.getRank()-2);
        
        if (aCard.getSelected())
            img = GrayFilter.createDisabledImage(img);
        
        g.drawImage(img, x, y, null);
        
        return true;
    }
    
    // изображение всех карт
    private ArrayList<BufferedImage> m_imgListSpades = null;
    private ArrayList<BufferedImage> m_imgListClubs = null;
    private ArrayList<BufferedImage> m_imgListDiamonds = null;
    private ArrayList<BufferedImage> m_imgListHearts = null;

    // ширина читаемого избражения
    public static final int CARD_WIDTH = 74;
    // высота читаемого избражения
    public static final int CARD_HEIGHT = 114;
}
